home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / GENCSRC.ZIP / WHATNEXT.C < prev    next >
C/C++ Source or Header  |  1987-11-21  |  4KB  |  74 lines

  1. /* *************************************************************** */
  2. /* This program reads a series of words from the command line,     */
  3. /* and displays all but the last on the monitor. The last is a     */
  4. /* series of characters which are used as input comparisons. One   */
  5. /* character is read from the keyboard. If it is one of the        */
  6. /* characters in the comparison list, its number is returned to    */
  7. /* DOS as the errorlevel command. If the character does not exist  */
  8. /* in the list, a zero is returned. Example follows;               */
  9. /*                                                                 */
  10. /* WHATNEXT What model do you want? ALR%3T                         */
  11. /*                                                                 */
  12. /* What model do you want?      <---- displayed on monitor         */
  13. /*    If key a or A is hit, errorlevel 1 is returned.              */
  14. /*    If key l or L is hit, errorlevel 2 is returned.              */
  15. /*    If key r or R is hit, errorlevel 3 is returned.              */
  16. /*    If key % is hit, errorlevel 4 is returned.                   */
  17. /*    If key 3 is hit, errorlevel 5 is returned.                   */
  18. /*    If key t or T is hit, errorlevel 6 is returned.              */
  19. /*    If any other key is hit, errorlevel 0 is returned.           */
  20. /*                                                                 */
  21. /*  The question must be on one line.                              */
  22. /*  Up to nine different keys can be used.                         */
  23. /*  The errorlevel can be interpreted in a batchfile.              */
  24. /* *************************************************************** */
  25.  
  26. #include "stdio.h"
  27. #include "ctype.h"
  28. #include "conio.h"
  29. #include "process.h"
  30.  
  31. main(int number,char *name[])
  32. {
  33. int index;                  /* a counter and incrementing variable */
  34. int c;                     /* the character read in for comparison */
  35. int code;                  /* the resulting errorlevel returned to */
  36. char next_char;                    /* used for the comparison loop */
  37. char *point;               /* a dummy pointer used for convenience */
  38.  
  39.                      /* At least one group must be used for this   */
  40.                      /* filename, and one group used for the       */
  41.                      /* required fields, so less than three allows */
  42.                      /* for no question.                           */
  43.    if (number < 3) {
  44.       printf("No question given on command line\n");
  45.       exit(0);
  46.    }
  47.  
  48.                          /* print out words 2 to n-1, the question */
  49.    number--;
  50.    for(index = 1;index < number;index++) {
  51.       printf("%s ",name[index]);
  52.    }
  53.  
  54.                    /* get the users response and make it uppercase */
  55.    c = getch();
  56.    printf("%c\n",c);
  57.    if (islower(c))
  58.       c = toupper(c);
  59.    point = name[number];/* point to the last pointer on the inputs */
  60.  
  61.    code = 0;
  62.    index = 0;
  63.    do {            /* search across allowed responses in last word */
  64.       next_char = *(point + index);
  65.       if (islower(next_char))
  66.          next_char = toupper(next_char);      /* make it uppercase */
  67.       if(next_char == c)                    /* if a match is found */
  68.          code = index + 1;         /* save the number of the match */
  69.       index++;
  70.    } while (*(point + index));      /* until NULL terminator found */
  71.  
  72.    exit(code);               /* return the errorcode to the system */
  73. }
  74.